package cn.internship.modules.manage.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import cn.internship.modules.manage.entity.dto.MajorSearch;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.internship.modules.manage.entity.MajorInfoEntity;
import cn.internship.modules.manage.service.MajorInfoService;
import cn.internship.common.utils.PageUtils;
import cn.internship.common.utils.R;



/**
 * 
 *
 * @author haha
 * @email haha@gmail.com
 * @date 2023-02-20 15:58:08
 */
@RestController
@RequestMapping("manage/majorinfo")
public class MajorInfoController {
    @Autowired
    private MajorInfoService majorInfoService;

//    /**
//     * 列表
//     */
//    @RequestMapping("/list")
//    @RequiresPermissions("manage:majorinfo:list")
//    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = majorInfoService.queryPage(params);
//
//        return R.ok().put("page", page);
//    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("manage:majorinfo:list")
    public R list(MajorSearch search){
        PageUtils page = majorInfoService.listByPage(search);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("manage:majorinfo:info")
    public R info(@PathVariable("id") Integer id){
		MajorInfoEntity majorInfo = majorInfoService.getById(id);

        return R.ok().put("majorInfo", majorInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("manage:majorinfo:save")
    public R save(@RequestBody MajorInfoEntity majorInfo){
        majorInfo.setCreateTime(new Date());
		majorInfoService.save(majorInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("manage:majorinfo:update")
    public R update(@RequestBody MajorInfoEntity majorInfo){
		majorInfoService.updateById(majorInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("manage:majorinfo:delete")
    public R delete(@RequestBody Integer[] ids){
		majorInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 下拉列表
     * @return
     */
    @RequestMapping("/dropList")
    public R dropList(){
        return R.ok().put("data",majorInfoService.list());
    }
}
